<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" name="" id="num1" value="" />
		<select id="fh">
			<option value="">请选择符号</option>
			<option value="+">+</option>
			<option value="-">-</option>
			<option value="*">*</option>
			<option value="/">/</option>
		</select>
		<input type="text" name="" id="num2" value="" />
	<button type="button" onclick="js1()">计算</button>
		<input type="text" name="" id="sum" value="" />
	</body>
	<script type="text/javascript">
		// 方法1
		function js1(){
			var fh = document.getElementById('fh').value;
			var num1 = document.getElementById('num1').value;
			var num2 = document.getElementById('num2').value;
				
			if(num1 == ''){
				alert('请输入第一个值');
			}else if(num2 == ''){
				alert('请输入第二个值');
			}else{
				num1 = Number(num1);
				num2 = Number(num2);
				
				var sum;
				switch(fh){
					case "+":
						sum = num1 + num2;
						break;
					case "-":
						sum = num1 - num2;
						break;
					case "*":
						sum = num1 * num2;
						break;
					case "/":
						sum = num1 / num2;
						break;
					default:
						alert('请选择符号');
						break;
				}
				
				var sumobj = document.getElementById('sum');
					sumobj.value = sum;
			}
			
			
		}
		// 方法2
		function js2(){
			var fh = document.getElementById('fh').value;
			var num1 = document.getElementById('num1').value;
			var num2 = document.getElementById('num2').value;
			var sum = num1+fh+num2;
			var sum1 = eval(sum);
			var sumobj = document.getElementById('sum');
				sumobj.value = sum1;
		}
	</script>
</html>
